﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import reprise.commands.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.services.*;

    public class PlayEffectSoundCommand extends Command {

		[Inject]
        public var event:InfoEvent;
		[Inject]
        public var sounds:SoundService;
		[Inject]
        public var gameStateModel:GameStateModel;
		[Inject]
        public var environmentModel:EnvironmentModel;
		[Inject]
        public var fileInfoModel:FileInfoModel;
        private var _volume:int;
        private var _delay:int;

        override public function execute():void{
            if (!this.gameStateModel.initWorldComplete){
                return;
            };
            var _local1:Object = this.event.info;
            if (_local1){
                this._volume = _local1[EventConstants.SOUND_VOLUME];
                this._delay = _local1[EventConstants.SOUND_DELAY];
            } else {
                this._volume = 1;
                this._delay = 0;
            };
            if (this._delay == 0){
                this.playSound();
            } else {
                this.startDelayTimer();
            };
        }
        private function playSound():void{
            if (this.sounds.effectsMuted){
                this._volume = 0;
            };
            this.sounds.playSound(this.getURL(), 1, this._volume);
        }
        private function getURL():String{
            var _local1 = (("assets/sounds/" + this.event.id) + ".mp3");
            if (!this.environmentModel.localVersion){
                _local1 = this.fileInfoModel.getCdnUrl(_local1);
            };
            return (_local1);
        }
        private function startDelayTimer():void{
            var _local1:TimerCommand = new TimerCommand(this._delay);
            _local1.addEventListener(Event.COMPLETE, this.delayCommand_complete);
            _local1.execute();
        }
        private function delayCommand_complete(_arg1:Event):void{
            var _local2:TimerCommand = TimerCommand(_arg1.target);
            _local2.removeEventListener(Event.COMPLETE, this.delayCommand_complete);
            _local2 = null;
            this.playSound();
        }

    }
}//package net.wooga.pets.controllers 
